/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.hycreate.platform.modules.crm.findcustomer;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hycreate.platform.common.persistence.Page;
import com.hycreate.platform.common.service.CrudService;
import com.hycreate.platform.common.utils.IdGen;

/**
 * 客户查询Service
 * @author 方志钧
 * @version 2016-12-05
 */
@Service
@Transactional(readOnly = true)
public class FindCustomerService extends CrudService<FindCustomerDao, FindCustomer> {
	@Autowired
	private FindCustomerDao findCustomerDao;

	public FindCustomer get(String id) {
		return super.get(id);
	}
	
	public List<FindCustomer> findList(FindCustomer findCustomer) {
		return super.findList(findCustomer);
	}
	
	public Page<FindCustomer> findPage(Page<FindCustomer> page, FindCustomer findCustomer) {
		return super.findPage(page, findCustomer);
	}
	
	@Transactional(readOnly = false)
	public void save(FindCustomer findCustomer) {
		super.save(findCustomer);
	}
	
	@Transactional(readOnly = false)
	public void delete(FindCustomer findCustomer) {
		findCustomerDao.delete(findCustomer);
	}

	public List<String> findAllNames() {
		return findCustomerDao.findAllNames();
	}
	
	/**
	 * 根据行业和公司名分页查询客户的集合 
	 * N表示name I表示industryName
	 * */
	public Page<FindCustomer> findCustomerPage(Page<FindCustomer> page, FindCustomer findCustomer) {
		findCustomer.setPage(page);
		page.setList(dao.findSomCustomersByNI(findCustomer));
		return page;
	}
	
	/**
	 * 删除客户行业
	 * @param customerId
	 * @param industryId
	 */
	@Transactional(readOnly = false)
	public void deleteIndustry(String customerId,String industryId) {
		findCustomerDao.deleteIndustry(customerId,industryId);
	}
	
	/**
	 * 为客户添加行业
	 * */
	@Transactional(readOnly = false)
	public void addIndustryForCustomer(String uuid, String customerId,
			String industryId) {
		findCustomerDao.addIndustryForCustomer(uuid,customerId,industryId);
	}
	
	/**
	 * 验证该客户行业是否存在
	 * @param customerId
	 * @param industryId
	 * @return
	 */
	public int isExist(String customerId,String industryId){
		return findCustomerDao.isExist(customerId,industryId);
	}

	/**
	 * 查看我的收藏
	 * */
	public Page<FindCustomer> findMyCollectCustomer(Page<FindCustomer> page, FindCustomer findCustomer,String userId) {
		findCustomer.setPage(page);
		page.setList(dao.findMyCollectCustomer(userId));
		return page;
	}
	
	/**
	 * 获取当前页所有客户
	 * @param custoemrIds 当前页所有客户的id的数组
	 * @return 返回EXCEL模板类的集合
	 */
	public List<ExcelCustomerMould> findListByIds(String[] custoemrIds) {
		return findCustomerDao.findListByIds(custoemrIds);
	}
	
	/**
	 * 取消收藏
	 * */
	@Transactional(readOnly = false)
	public void cacleCollect(String userId, String customerId) {
		findCustomerDao.cacleCollect(userId,customerId);
	}
	
	/**
	 * 获得指定客户的收藏者ID
	 * @param customerId
	 * @return 收藏用户的id
	 */
	public String getCustomerCollecterId(String customerId) {
		return findCustomerDao.getCustomerCollecterId(customerId);
	}
	
	/**验证客户是否已被他人添加*/
	public String alreadyCollect(String customerId) {
		
		return findCustomerDao.alreadyCollect(customerId);
	}
	/**
	 * 添加到我的客户
	 * @param userId
	 * @param customerId
	 */
	@Transactional(readOnly = false)
	public void addMyCustomer(String userId, String customerId) {
		findCustomerDao.addMyCustomer(IdGen.uuid(),userId, customerId);
	}

	/**
	 * 修改用户的最近联系时间
	 */
	@Transactional(readOnly = false)
	public void updateLastContant(String customerId){
		dao.updateLastContant(customerId);
	}
	
	
	/**
	 * 删除用户的联系记录
	 */
	@Transactional(readOnly = false)
	public void delCustomerContant(String contactid){
		
		dao.delCustomerContant(contactid);
	}

}